#include "OgreCgPlugin.h"
#include "OgreCgProgram.h"
#include "OgreRoot.h"

namespace Ogre
{
	CgPlugin* cgPlugin;
#ifndef OGRE_STATIC_LIB
	extern "C" void _OgreCgPluginExport dllStartPlugin(void)
	{
		cgPlugin = OGRE_NEW CgPlugin();

		Root::getSingleton().installPlugin(cgPlugin);
	}

	extern "C" void _OgreCgPluginExport dllStopPlugin(void)
	{
		Root::getSingleton().uninstallPlugin(cgPlugin);
		OGRE_DELETE cgPlugin;
	}
#endif

	void checkForCgError(const String& ogreMethod, const String& errorTextPrefix, CGContext context)
	{
		CGerror error = cgGetError();
		if (error != CG_NO_ERROR)
		{
			String msg = errorTextPrefix + cgGetErrorString(error);

			if (error == CG_COMPILER_ERROR)
			{
				msg = msg + "\n" + cgGetLastListing(context);
			}
			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msg, ogreMethod);
		}
	}
}
